//
//  JXMainController.swift
//  01-weiboSwift
//
//  Created by TwistFate on 16/2/26.
//  Copyright © 2016年 TwistFate. All rights reserved.
//

import UIKit

class JXMainController: UITabBarController ,JXCustomTabBarDelegate{
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        
        let customTabBar = JXCustomTabBar()
        
        customTabBar.customDelegate = self
        
        setValue(customTabBar, forKey: "tabBar")

        addControllers()
        
    }
    
    func addControllers(){
        let homeVC = JXHomeController()
        setChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        
        let messageVC = JXMessageController()
        setChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let midVC = UIViewController()
        addChildViewController(midVC)
        
        let discoverVC = JXDiscoverController()
        setChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        
        let profileVC = JXProfileController()
        setChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    func setChildViewController(viewController: UIViewController , title: String , imageName:String) {
        viewController.title=title
        viewController.tabBarItem.image=UIImage(named:imageName)
        
        viewController.tabBarItem.selectedImage=UIImage(named:imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        viewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        
        //        let navVC = viewController as! UINavigationController
        addChildViewController(UINavigationController(rootViewController: viewController));
    }
    
    
    func JXCustomTabBarClick() {
        print("k可以modal了啊")
    }
}
